package com.ruoyi.system.service.impl;

import com.ruoyi.system.entity.EnterpriseBasic;
import com.ruoyi.system.mapper.EnterpriseBasicMapper;
import com.ruoyi.system.service.EnterpriseBasicService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 企业基础信息(EnterpriseBasic)表服务实现类
 *
 * @author makejava
 * @since 2023-03-23 08:51:49
 */
@Service("enterpriseBasicService")
public class EnterpriseBasicServiceImpl implements EnterpriseBasicService {
    @Resource
    private EnterpriseBasicMapper enterpriseBasicDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public EnterpriseBasic queryById(Integer id) {
        return this.enterpriseBasicDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param enterpriseBasic 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<EnterpriseBasic> queryByPage(EnterpriseBasic enterpriseBasic, PageRequest pageRequest) {
        long total = this.enterpriseBasicDao.count(enterpriseBasic);
        return new PageImpl<>(this.enterpriseBasicDao.queryAllByLimit(enterpriseBasic, pageRequest), pageRequest, total);
    }

    @Override
    public List<EnterpriseBasic> queryAll(EnterpriseBasic enterpriseBasic) {
        return enterpriseBasicDao.queryAll(enterpriseBasic);
    }

    /**
     * 新增数据
     *
     * @param enterpriseBasic 实例对象
     * @return 实例对象
     */
    @Override
    public EnterpriseBasic insert(EnterpriseBasic enterpriseBasic) {
        this.enterpriseBasicDao.insert(enterpriseBasic);
        return enterpriseBasic;
    }

    /**
     * 修改数据
     *
     * @param enterpriseBasic 实例对象
     * @return 实例对象
     */
    @Override
    public EnterpriseBasic update(EnterpriseBasic enterpriseBasic) {
        this.enterpriseBasicDao.update(enterpriseBasic);
        return this.queryById(enterpriseBasic.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.enterpriseBasicDao.deleteById(id) > 0;
    }
}
